home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / sea of chaos / sea_install.msi / _15C39AAA7726369D39812BD40F01CF6A / _239CFDB43BF94EBE922B7374EB682994 < prev    next >
Text File  |  2005-03-02  |  2KB  |  85 lines

  1. //water vertex shader:
  2. //adjusts alpha based on angle between surface normal and eye
  3. //1 directional light also applied
  4. //also does environmental reflection off water (env map should be fixed relative to axises)
  5. //has projective reflections
  6. //Luke Lenhart
  7. //(C)2004-2005 Digipen Institute of Technology
  8.  
  9.  
  10. //world,view,projection transform
  11. float4x4 matWorldViewProj;
  12.  
  13. //projective mapping matrix (maps projected coords to texture coords)
  14. float4x4 matProjTxt;
  15.  
  16. //camera position in world space
  17. float4 cameraPos;
  18.  
  19. //directional light (assumed to be the sun)
  20. float4 lgtDirection;
  21.  
  22. //shader input
  23. struct VS_INPUT
  24. {
  25.     float4 Pos : POSITION;
  26.     float4 Normal : NORMAL;
  27.     float4 Clr: COLOR0;
  28. };
  29.  
  30. //shader output
  31. struct VS_OUTPUT
  32. {
  33.     float4 Pos : POSITION;
  34.     float4 Color : COLOR;
  35.     //float2 Tex0 : TEXCOORD0;
  36.     float3 EnvTex : TEXCOORD1;
  37.     float3 Pos2 : TEXCOORD2;
  38.     float4 ProjTxt : TEXCOORD3;
  39.     float CamDist : TEXCOORD4;
  40.     float CamDist2 : TEXCOORD5;
  41.     //float FogClr : TEXCOORD6;
  42. };
  43.  
  44. //shader code
  45. VS_OUTPUT VShader(VS_INPUT In)
  46. {
  47.     VS_OUTPUT Out;
  48.     
  49.     //tex coord generated from position
  50.     //Out.Tex0=In.Pos;
  51.     
  52.     //out position
  53.     Out.Pos=mul(matWorldViewProj,In.Pos);
  54.     Out.Pos2=In.Pos;
  55.     
  56.     //calc directional light color
  57.     Out.Color=dot(In.Normal,lgtDirection)*In.Clr;
  58.     
  59.     //calc alpha based dot between vertex normal and vector from vertex to camera
  60.     //taken to a high power to spread translucent range over more of the angle range
  61.     //done in world space
  62.     float3 vecEyeToVertex=normalize(cameraPos-In.Pos);
  63.     float alpha=pow(1.0f-dot(vecEyeToVertex,In.Normal), 15.0f);
  64.     Out.Color+=alpha*float4(0.2f,0.2f,0.2f,0.0f);
  65.     Out.Color.a=(0.6f+alpha)*In.Clr.a*0.8f;
  66.     Out.Color+=float4(0.1f,0.1f,0.1f,0.1f);
  67.     
  68.     //calc env reflection vector (done in world space)
  69.     float3 tranNorm=In.Normal.xyz;
  70.     Out.EnvTex=reflect(-vecEyeToVertex,tranNorm);
  71.     
  72.     //calculation projective texture coordinate
  73.     Out.ProjTxt=mul(matProjTxt,In.Pos);
  74.     
  75.     //calc dist from vert to camera
  76.     Out.CamDist=distance(cameraPos.xyz,In.Pos.xyz);
  77.     Out.CamDist2=sqrt(Out.CamDist);
  78.     
  79.     //calc fog color
  80.     //Out.FogClr=saturate(log(Out.CamDist*0.0067f)*0.06f - 0.1f);
  81.     
  82.     //spit out the results
  83.     return Out;
  84. }
  85.